<?php
foreach ($Comments as $commentObject) {
    $comment = $commentObject['content'];
    $relate = $commentObject['relate'];
    $persion = $commentObject['persion'];
    ?>
    <div class="comment_person">
        <div class="comment_owner">
            <img src="<?php echo Yii::app()->baseUrl; ?>/images/ProfileImage/<?php echo $persion->Avatar; ?>">
        </div>
        <div class="comment_content">
            <div class="comment_text">
                <p>
                    <?php echo $comment->NoiDung; ?>
                    <!--Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.-->
                </p>

            </div>
            <div class="comment_details">
                <h4 class="owner_name"><?php echo $persion->BiDanh; ?></h4>
                <div class="article_func">
                    <div class="information_function button_40">
                        <img class="icon_32" src="<?php echo Yii::app()->baseUrl; ?>/images/Icons/info-light.png">
                        <div class="information_details">

                        </div>
                    </div>
                    <div class="comment_function button_40 toggle-reply-comment">
                        <img class="icon_32" src="<?php echo Yii::app()->baseUrl; ?>/images/Icons/Comment-light.png">

                    </div>
                </div>
            </div>

        </div>
        <div class="comment_reply">
            <?php
            foreach ($relate as $RepComment) {
                $RepPersion = $RepComment['persion'];
                $RepContent = $RepComment['content'];
                ?>
                <div class="comment_child">
                    <div class="comment_owner">
                        <img src="<?php echo Yii::app()->baseUrl; ?>/images/ProfileImage/<?php echo $RepPersion->Avatar; ?>">
                    </div>
                    <div class="comment_content">
                        <div class="comment_text">
                            <p>
                                <?php echo $RepContent->NoiDung; ?>
                                <!--Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.-->
                            </p>

                        </div>
                        <div class="comment_details">
                            <h4 class="owner_name"><?php echo $RepPersion->BiDanh; ?></h4>
                            <div class="article_func">
                                <div class="information_function button_40">
                                    <img class="icon_32" src="<?php echo Yii::app()->baseUrl; ?>/images/Icons/info-light.png">
                                    <div class="information_details">

                                    </div>
                                </div>
                                <div class="comment_function button_40">
                                    <img class="icon_32" src="<?php echo Yii::app()->baseUrl; ?>/images/Icons/Comment-light.png">

                                </div>
                            </div>
                        </div>

                    </div>

                </div>
            <?php } ?>

            <div class="comment_child reply-box" style="display: none;">
                <form class="reply_comment_form">
                    <textarea name="content" class="ckeditor reply_comment_content"></textarea>
                    <button class="button_base submit-reply-comment" data-id="<?php echo $comment->Id; ?>">Gửi</button>
                </form>
            </div>
        </div>
    </div>
<?php } ?>
<script>
    $(document).ready(function() {
//        CKEDITOR.replaceClass('reply_comment_content');
        $('.reply_comment_content').ckeditor();
        $('.toggle-reply-comment').click(function() {
//            'àasfg');
            $(this).parents('.comment_person').find('.reply-box').toggle(300);
        });
//        $('.reply_comment_content').submit(function(){
//            $content = $(this).find('.reply_comment_content').html();
//            console.log($content);e.preventDefault();
//            return false;
//        });
        $('.submit-reply-comment').click(function(e) {
            for (instance in CKEDITOR.instances)
                CKEDITOR.instances[instance].updateElement();
            var Id = $(this).attr('data-id');
            var content = $(this).parent().find('.reply_comment_content').val();
            URL = '<?php echo Yii::app()->createUrl('User/ReplyComment'); ?>';
            $.post(URL, {Id: Id, Content: content}, function(data) {
                if (data === 'success') {
                    getComment();
                }
            });
            e.preventDefault();
        });
    });
</script>